home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / P_ROBO31.ZIP / HOTSHOT.PR < prev    next >
Text File  |  1993-02-21  |  5KB  |  147 lines

  1.  
  2. (**************************************************************************)
  3. (*                             W A R N I N G                              *)
  4. (*                                                                        *)
  5. (*  This Robot has NOT been designed to take advantage of the advanced    *)
  6. (*  features of P-ROBOTS, such as, Shields, Fuel, Teams or Obstructions.  *)
  7. (**************************************************************************)
  8.  
  9.   PROCEDURE HotShot;
  10.   {
  11.    Author: David Malmberg
  12.  
  13.    Strategy:  Stay in one place.  Find a foe.  Take a shot.
  14.    Keep improving aim and shooting until foe is lost from sights.
  15.    Then move sights (scanning) to adjacent target area.  If
  16.    hit, then move to another random position on playing field.
  17.    If the Robot scans two complete circles (720 degrees) without
  18.    finding a foe in shooting range, move to another spot on the
  19.    field.  (This will avoid "stand-offs" where opponents stay
  20.    just out of range of one another.)
  21.  
  22.    This Robot should be VERY effective against foes which
  23.    are stopped or are moving slowly.  It will be less effective
  24.    against Robots traveling at high speeds.
  25.   }
  26.  
  27.  
  28.   VAR { HotShot "Global" variables }
  29.  
  30.     Angle, { Scanning angle }
  31.     Last_Damage, { Robot's Last damage value }
  32.     Range, { Range/Distance to foe }
  33.     Sweep, { "Sweep count" -- when = 36, Robot has scanned 720 degrees }
  34.     Delta          : Integer; { Scanning arc }
  35.  
  36.  
  37.     PROCEDURE Aim(VAR Ang : Integer; VAR Arc : Integer);
  38. {
  39.  Improve aim by doing a binary search of the target area.
  40.  I.E., divide the target area in two equal pieces and redefine
  41.  the target area to be the piece where the foe is found.
  42.  If the foe is not found, expand the search area to the
  43.  maximum arc of plus or minus 10 degrees.
  44. }
  45.     BEGIN
  46.       Arc := Arc DIV 2; { Divide search area in two. }
  47.       IF scan(Ang-Arc, Arc) <> 0 { Check piece "below" target angle. }
  48.         THEN Ang := Ang-Arc { If foe found, redefine target angle. }
  49.         ELSE IF scan(Ang+Arc, Arc) <> 0 { Check piece "above" target angle. }
  50.           THEN Ang := Ang+Arc { If foe found, redefine target angle. }
  51.           ELSE Arc := 10;
  52.       { Foe not found in either piece, expand search area to maximum arc. }
  53.     END; {Aim}
  54.  
  55.  
  56.     PROCEDURE BlastThem;
  57.     BEGIN
  58.       Angle := 10;
  59.       REPEAT
  60.         Delta := 10; { Start with widest scanning arc. }
  61.         Range := scan(Angle, Delta);
  62.         WHILE (Range > 40) AND (ObjectScanned = Enemy)
  63.           AND (Range < MaxMissileRange) DO
  64.         { Must be far enough away to avoid self-damage. }
  65.           BEGIN
  66.             Aim(Angle, Delta); { Improve aim. }
  67.             Cannon(Angle, Range); { Fire!! }
  68.             Range := scan(Angle, Delta); { Is foe still in sights? }
  69.           END;
  70.         Angle := Angle+20; { Look in adjacent target area. }
  71.       UNTIL Angle > 360;
  72.     END;
  73.  
  74.  
  75.     PROCEDURE GOTO(x, y : Integer);
  76.       { Go to location X,Y on playing field. }
  77.     VAR Heading    : Integer;
  78.     BEGIN
  79.       { Find the heading we need to get to the desired spot. }
  80.       Heading := Angle_To(x, y);
  81.  
  82.       { Keep traveling at top speed until we are within 150 meters }
  83.       WHILE (distance(loc_x, loc_y, x, y) > 150) DO
  84.         BEGIN
  85.           Drive(Heading, MaxSpeed);
  86.           BlastThem;
  87.         END;
  88.  
  89.       { Cut speed, and creep the rest of the way. }
  90.       WHILE (distance(loc_x, loc_y, x, y) > 20) DO
  91.         BEGIN
  92.           Drive(Heading, 20);
  93.           BlastThem;
  94.         END;
  95.  
  96.       { Stop driving, should coast to a stop. }
  97.       Drive(Heading, 0); {I.E., Stop}
  98.     END; {GoTo(X,Y)}
  99.  
  100.  
  101.     FUNCTION Hurt  : Boolean;
  102.       { Checks if Robot has incurred any new damage. }
  103.     VAR Curr_Damage : Integer;
  104.       Answer         : Boolean;
  105.     BEGIN
  106.       Curr_Damage := damage;
  107.       Answer := (Curr_Damage > Last_Damage);
  108.       Last_Damage := Curr_Damage;
  109.       Hurt := Answer;
  110.     END; {Hurt}
  111.  
  112.  
  113.     PROCEDURE Move;
  114.       { Move to a random spot on the playing field. }
  115.     VAR x, y       : Integer;
  116.     BEGIN
  117.       Sweep := 0; { Reset Sweep counter to zero. }
  118.       x := Random(900)+50;
  119.       y := Random(900)+50;
  120.       GOTO(x, y);
  121.     END; {Move}
  122.  
  123.  
  124.   BEGIN {HotShot Main}
  125.     Angle := Angle_To(500, 500);
  126.     { Start scanning for foes in center of field. }
  127.     Sweep := 0; { Initialize Sweep counter to zero. }
  128.     REPEAT { Until Dead or Winner }
  129.       Delta := 10; { Start with widest scanning arc. }
  130.       Range := scan(Angle, Delta);
  131.       WHILE (Range > 40) AND (Range < 700) DO
  132.         { Must be far enough away to avoid self-damage. }
  133.         BEGIN
  134.           Sweep := 0; { Found foe, so reset Sweep to zero }
  135.           Aim(Angle, Delta); { Improve aim. }
  136.           cannon(Angle, Range); { Fire!! }
  137.           Range := scan(Angle, Delta); { Is foe still in sights? }
  138.         END;
  139.       Angle := Angle+20; { Look in adjacent target area. }
  140.       Sweep := Sweep+1;
  141.       IF Hurt OR (Sweep = 36) THEN Move;
  142.       { If hit or have scanned two full circles, move elsewhere. }
  143.     UNTIL Dead OR Winner;
  144.   END; {HotShot Main}
  145.  
  146.  
  147.